package cn.edu.cug.cs.gtl.gsm.jdbc;

import cn.edu.cug.cs.gtl.common.Identifier;
import cn.edu.cug.cs.gtl.gsm.PaginationStorageManager;
import cn.edu.cug.cs.gtl.io.storage.StorageManager;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * gsm_jdbc_sm_meta
 * long table_size;
 * int page_size;
 * long next_page_low_id;
 * long next_page_high_id;
 * varchar empty_pages;用分号分隔
 *
 * gsm_jdbc_sm_idx
 * long page_low_id;
 * long page_high_id;
 * long length;
 * varchar internal_pages;用分号分隔
 *
 * gsm_jdbc_sm_data
 * long page_low_id;
 * long page_high_id;
 * varchar page_content;//byte[] <---> String
 */
public abstract class JDBCStorageManager extends PaginationStorageManager {

    /**
     * @param collectionSize
     * @param pageSize
     */
    public JDBCStorageManager(long collectionSize, int pageSize) {
        super(collectionSize, pageSize);
    }

    /**
     * @param baseName
     * @param collectionSize
     * @param pageSize
     */
    public JDBCStorageManager(String baseName, long collectionSize, int pageSize) {
        super(baseName, collectionSize, pageSize);
    }

    /**
     *
     * @param connection
     * @param dataTypeName
     * @return
     * @throws SQLException
     */
    public static boolean supportsDataType(Connection connection, String dataTypeName) throws SQLException {
        ResultSet rs = connection.getMetaData().getTypeInfo();
        while (rs.next()){
//            int c = rs.getMetaData().getColumnCount();
//            for(int i=1;i<=c;++i)
//                System.out.print(rs.getString(i)+"  ");
//            System.out.println();
            if(rs.getString(1).trim().toLowerCase().equals(dataTypeName.trim().toLowerCase())) {
                rs.close();
                return true;
            }
        }
        rs.close();
        return false;
    }
}
